/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.gw2InfoViewer.views;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import org.gw2InfoViewer.maps.MapNames;
import org.gw2InfoViewer.maps.WorldNames;
import org.gw2InfoViewer.models.Options;
/**
*
* @author Robert Smieja
*/
public class OptionsForm extends javax.swing.JDialog {
private WorldNames worldNames;
private MapNames mapNames;
private MainView parent;
/**
* Creates new form OptionsForm
*/
public OptionsForm(MainView parent, boolean modal, Options options, WorldNames worldNames, MapNames mapNames) {
super(parent, modal);
this.worldNames = worldNames;
this.mapNames = mapNames;
this.parent = parent;
initComponents();
setOptions(options, worldNames, mapNames);
}
public void setOptions(Options options, WorldNames worldNames, MapNames mapNames) {
DefaultComboBoxModel worldComboBoxModel = new DefaultComboBoxModel();
DefaultComboBoxModel mapComboBoxModel = new DefaultComboBoxModel();
mapComboBoxModel.addElement("None");
worldComboBoxModel.addElement("None");
List<String> sortedMapNames = new ArrayList<String>();
sortedMapNames.addAll(worldNames.getMap().values());
Collections.sort(sortedMapNames);
for (Iterator<String> it = sortedMapNames.iterator(); it.hasNext();) {
mapComboBoxModel.addElement(it.next());
}
List<String> sortedWorldNames = new ArrayList<String>();
sortedWorldNames.addAll(worldNames.getMap().values());
Collections.sort(sortedWorldNames);
for (Iterator<String> it = sortedWorldNames.iterator(); it.hasNext();) {
worldComboBoxModel.addElement(it.next());
}
mapComboBox.setModel(mapComboBoxModel);
worldComboBox.setModel(worldComboBoxModel);
if (options.getMap() != 0) {
mapComboBox.setSelectedItem(mapNames.getMap().get(options.getMap()));
} else {
mapComboBox.setSelectedItem("None");
}
if (options.getWorld() != 0) {
worldComboBox.setSelectedItem(worldNames.getMap().get(options.getWorld()));
} else {
worldComboBox.setSelectedItem("None");
}
eventIdText.setText(options.getEventId());
matchIdText.setText(options.getMatchId().toString());
proxyEnabledCheckbox.setSelected(options.isProxyEnabled());
proxyAddressText.setText(options.getProxyAddress());
proxyPortText.setText(options.getProxyPort().toString());
}
public Options getOptions() {
Options options = new Options();
if (mapComboBox.getSelectedItem().toString() == "None") {
options.setMap(0);
} else {
options.setMap(mapNames.getMap().inverse().get(mapComboBox.getSelectedItem()));
}
if (worldComboBox.getSelectedItem().toString() == "None") {
options.setMap(0);
} else {
options.setWorld(worldNames.getMap().inverse().get(worldComboBox.getSelectedItem()));
}
options.setEventId(eventIdText.getText());
options.setMatchId(Integer.parseInt(matchIdText.getText()));
options.setProxyEnabled(proxyEnabledCheckbox.isSelected());
options.setProxyAddress(proxyAddressText.getText());
options.setProxyPort(Integer.parseInt(proxyPortText.getText()));
return options;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
worldComboBox = new javax.swing.JComboBox();
proxyEnabledCheckbox = new javax.swing.JCheckBox();
worldLabel = new javax.swing.JLabel();
mapLabel = new javax.swing.JLabel();
eventIdLabel = new javax.swing.JLabel();
matchId = new javax.swing.JLabel();
eventIdText = new javax.swing.JTextField();
proxyAddressLabel = new javax.swing.JLabel();
proxyPortText = new javax.swing.JTextField();
proxyLabelAddress = new javax.swing.JLabel();
proxyAddressText = new javax.swing.JTextField();
matchIdText = new javax.swing.JTextField();
mapComboBox = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
worldComboBox.setMaximumRowCount(15);
worldComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Loading..." }));
worldComboBox.setPreferredSize(new java.awt.Dimension(150, 20));
proxyEnabledCheckbox.setText("Use a Proxy:");
proxyEnabledCheckbox.setBorder(null);
proxyEnabledCheckbox.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
proxyEnabledCheckbox.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
worldLabel.setText("World:");
mapLabel.setText("Map:");
eventIdLabel.setText("Event ID:");
matchId.setText("Match ID:");
eventIdText.setText("Loading...");
eventIdText.setPreferredSize(new java.awt.Dimension(200, 20));
proxyAddressLabel.setText("Address:");
proxyPortText.setText("Loading...");
proxyPortText.setPreferredSize(new java.awt.Dimension(60, 20));
org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, proxyEnabledCheckbox, org.jdesktop.beansbinding.ELProperty.create("${selected}"), proxyPortText, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
proxyLabelAddress.setText("Port:");
proxyAddressText.setText("Loading...");
proxyAddressText.setPreferredSize(new java.awt.Dimension(200, 20));
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, proxyEnabledCheckbox, org.jdesktop.beansbinding.ELProperty.create("${selected}"), proxyAddressText, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
matchIdText.setText("Loading...");
matchIdText.setPreferredSize(new java.awt.Dimension(60, 20));
mapComboBox.setMaximumRowCount(15);
mapComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Loading..." }));
mapComboBox.setPreferredSize(new java.awt.Dimension(200, 20));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(worldLabel)
.addComponent(mapLabel)
.addComponent(eventIdLabel)
.addComponent(matchId))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(matchIdText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(eventIdText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(mapComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(worldComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(proxyEnabledCheckbox)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(proxyAddressLabel)
.addComponent(proxyLabelAddress))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(proxyPortText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(proxyAddressText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(worldLabel)
.addComponent(worldComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(mapLabel)
.addComponent(mapComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(eventIdLabel)
.addComponent(eventIdText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(matchId)
.addComponent(matchIdText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(6, 6, 6)
.addComponent(proxyEnabledCheckbox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(proxyAddressLabel)
.addComponent(proxyAddressText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(proxyLabelAddress)
.addComponent(proxyPortText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
bindingGroup.bind();
pack();
}// </editor-fold>//GEN-END:initComponents
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
parent.setOptions(getOptions());
}//GEN-LAST:event_formWindowClosing
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel eventIdLabel;
private javax.swing.JTextField eventIdText;
private javax.swing.JComboBox mapComboBox;
private javax.swing.JLabel mapLabel;
private javax.swing.JLabel matchId;
private javax.swing.JTextField matchIdText;
private javax.swing.JLabel proxyAddressLabel;
private javax.swing.JTextField proxyAddressText;
private javax.swing.JCheckBox proxyEnabledCheckbox;
private javax.swing.JLabel proxyLabelAddress;
private javax.swing.JTextField proxyPortText;
private javax.swing.JComboBox worldComboBox;
private javax.swing.JLabel worldLabel;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration//GEN-END:variables
}